<template>
    <div>
        <el-table :data="tableData1" style="width: 100%">
            <el-table-column prop="name" label="名称" width="180" />
            <el-table-column label="优惠券类型" width="180">
                <template #default="scope">
                    {{ scope.row.type == 0 ? "全场赠券" : "" }}
                    {{ scope.row.type == 1 ? "会员赠券" : "" }}
                    {{ scope.row.type == 2 ? "购物赠券" : "" }}
                    {{ scope.row.type == 3 ? "注册赠券" : "" }}
                </template>
            </el-table-column>
            <el-table-column label="可使用商品">
                <template #default="scope">
                    {{ scope.row.platform == 0 ? "指定商品" : "全场通用" }}
                </template>
            </el-table-column>
            <el-table-column label="使用门槛">
                <template #default="scope">
                    满{{ scope.row.minPoint }}元可用
                </template>
            </el-table-column>
            <el-table-column label="面值">
                <template #default="scope">
                    {{ scope.row.amount }}元
                </template>
            </el-table-column>
            <el-table-column label="状态">
                <template #default="scope">
                    {{ dayjs(scope.row.endTime).format('YYYY-MM-DD') > nian ? '活动进行中' : '已过期' }}
                </template>
            </el-table-column>
        </el-table>
        <el-table :data="tableData1" style="width: 100%">
            <el-table-column label="失效期">
                <template #default="scope">
                    {{ dayjs(scope.row.startTime).format('YYYY-MM-DD') }}
                </template>
            </el-table-column>
            <el-table-column prop="publishCount" label="发行总量" />
            <el-table-column prop="receiveCount" label="已领取" />
            <el-table-column prop="count" label="带领取" />
            <el-table-column prop="useCount" label="已使用" />
            <el-table-column prop="count" label="未使用">
                <template #default="scope">

                </template>
            </el-table-column>
        </el-table>
    </div>
    <div class="admin">
        <div class="tanxin button">
            <p>筛选搜索</p>
            <div>
                <el-button @click="congzhi">重置</el-button>
                <el-button @click="getTableData">查询搜索</el-button>
            </div>
        </div>
        <div class="input">
            <el-form-item label="使用状态" v-model="type">
                <el-select placeholder="全部">
                    <el-option label="未使用" value="0" />
                    <el-option label="已使用" value="1" />
                    <el-option label="已过期" value="2" />
                </el-select>
            </el-form-item>
            <div style="margin-left: 20px;">
                <el-form-item label="订单编号">
                    <el-input v-model="name" placeholder="订单编号" class="el-input" type="text"></el-input>
                </el-form-item>
            </div>
        </div>
    </div>
    <div>
        <el-table :data="tableData" style="width: 100%">
            <el-table-column label="优惠码">
                <template #default="scope">
                </template>
            </el-table-column>
            <el-table-column prop="publishCount" label="领取会员" />
            <el-table-column prop="receiveCount" label="领取方式" />
            <el-table-column prop="count" label="领取时间" />
            <el-table-column prop="useCount" label="当前状态" />
            <el-table-column prop="count" label="使用时间">
            </el-table-column>
            <el-table-column prop="count" label="订单编号">
                <template #default="scope">

                </template>
            </el-table-column>

        </el-table>
        <el-pagination v-model:current-page="pagination.pageNum" v-model:page-size="pagination.pageSize"
            :page-sizes="[5, 10, 15, 20]" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
            @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
</template>

<script setup lang="ts">
import { ref, watch, reactive } from 'vue'
import type { Ref } from 'vue'
import { useRoute } from 'vue-router'
import * as api from '../../request/api'
import { ICouponCreateData } from '../../request/DYBApi'
import useTabel from '../../hooks/useGoods'
import dayjs from 'dayjs'
let date = new Date()
let nian = dayjs(date).format('YYYY-MM-DD')
// 类型
let type = ref()
// 订单编号
let name = ref()
// 传值过来的ID
let ids = ref<number>(Number(useRoute().query.id))
// 数据展示
let tableData1 = reactive<any[]>([])
let Ontab = async () => {
    console.log(ids.value);
    let arr = await api.yxadmin.GetCoupon({ id: ids.value })
    tableData1.push(arr)
}

   
Ontab()
// 封装请求和分页
let { tableData, getTableData, pagination, handleSizeChange, handleCurrentChange } = useTabel(api.yxadmin.GetCouponHistoryList,
    {
        orderSn: name.value, couponId: ids.value
    })

// 重置
let congzhi = () => {
    name.value = ''
    type.value = ''
    getTableData()
}
// 查询

</script>

<style scoped lang="scss">
.admin {
    margin: 20px;
    padding: 20px;
    padding-bottom: 30px;
    border: 1px solid #eee;
    border-radius: 5px;
    // box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
    border: 1px solid #eee;
    padding: 20px;
    box-sizing: border-box;

    .button {
        display: flex;
        align-items: center;
    }

    .input {
        margin-top: 20px;
        margin-left: 30px;
        font-size: 14px;
        align-items: center;
        margin-bottom: 20px;
        display: flex;
        justify-content: flex-start;
        flex-wrap: wrap;


    }
}
</style>